<%--
 *  File:    BeforeVisitPlanMain.jsp
 *  @Author: KentZhong 
 *  Date:    2009-10-9 10:02:44
 *
 *  Copyright (C) 2000 - 2009 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>


<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>


<%

  String strTableName = "";
  String strModuleName = "SFE";
  String privilegeCode = "H0258";
  String contextPath = request.getContextPath();
  java.util.HashMap userInfo = (java.util.HashMap)session.getAttribute("userinfo"); 
  Integer nCurUserId = (Integer)userInfo.get("userid");
  
   Integer contactid = null;
	//System.out.println("contactid1="+session.getAttribute("contactid"));
	//System.out.println("contactid2="+Integer.valueOf(request.getParameter("contactid")));
	 //System.out.println("contactid1="+request.getParameter("contactid"));
   if (request.getParameter("contactid") != null&&request.getParameter("contactid")!=""){
		 contactid = Integer.valueOf(request.getParameter("contactid"));
   }else {
		 contactid = (Integer)userInfo.get("userid");
   }
   //out.print(contactid);
%>
<%@ include file="/inc/Security.inc"%>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>
<html>
<head>
<title>VisitPlanFeedbackDetail</title>
 <%@ include file="/sfe/VisitPlanMaincss.inc"%>
<%
if("Y".equals(request.getParameter("isconfirm"))){
%>
<script>
	window.close();
</script>
<%return;
}%>	
<PageFlow:CheckPageFlow pageName="p_beforevisitplanmain"/>
<%

int nYear=((Integer)pageContext.getAttribute("year")).intValue();
int nMonth=((Integer)pageContext.getAttribute("monthofyear")).intValue();
int nWeek=((Integer)pageContext.getAttribute("weekofmonth")).intValue();
int nDay=((Integer)pageContext.getAttribute("dayofweek")).intValue();
Date dWeekStart=null;
Date planToday=null;
Calendar cal=Calendar.getInstance();
cal.clear();
cal.set(Calendar.YEAR,nYear);
cal.set(Calendar.MONTH,nMonth-1);
cal.set(Calendar.WEEK_OF_MONTH,nWeek);
cal.setFirstDayOfWeek(Calendar.MONDAY);
//cal.set(Calendar.DAY_OF_WEEK,nDay);
dWeekStart=cal.getTime();
cal.set(Calendar.DAY_OF_WEEK, nDay);
cal.add(Calendar.DATE, 1); 
planToday=cal.getTime();
//out.print(new java.sql.Date(planToday.getTime()));
if(nDay==1){
	planToday=dWeekStart;	
}
String[] weekLabelArrs=new String[]{"L_Monday","L_Tuesday","L_Wednesday","L_Thursday","L_Friday","L_Saturday","L_Sunday"};
String strFullDateFormat=label.getLabelName("L_FullDateFormat");
String strWeekShow=label.getLabelName(weekLabelArrs[nDay-1]);		
java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat(strFullDateFormat);
String flag = (String)pageContext.getAttribute("flag");
if(flag == null) flag = new String("");
String vflag = (String)pageContext.getAttribute("vflag");
if(vflag == null) vflag = new String("");

int nProcessID = -1;  
if (pageContext.getAttribute("processid") != null)
	nProcessID = ((Integer)pageContext.getAttribute("processid")).intValue();
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/Calendar.js"></script>
<%@ include file ="/inc/NewCalendar.inc" %>
<script language="JavaScript">
function page_close()
{
     window.close();
}
function page_setfileid(num,id)
{
	var myform = eval("document.cform");
	var fileobj=eval("myform.feedbackattrachid"+num);
			
	if(!isEmpty(id))
	{
		fileobj.value=id;
	}
	else
	{
		fileobj.value=" ";
	}
}

function page_closefeedback()
{
	var myform = eval("document.cform");
	myform.actionname.value = "close";
 	myform.target="_self";
 	isRunning = true;
 	myform.submit();
}
function page_back(){
    var strUrl="";
    strUrl="VisitPlanEditOneDay.jsp?ishistory=<custom:write property='ishistory'/>&customerid=<custom:write property='customerid'/>&processid=<custom:write property='processid'/>&uprocessid=<custom:write property='processid'/>&contactid=<custom:write property='contactid'/>&globalpccode=<custom:write property='globalpccode'/>";
    strUrl=strUrl+"&year=<custom:write property='year'/>&monthofyear=<custom:write property='monthofyear'/>&weekofmonth=<custom:write property='weekofmonth'/>&dayofweek=<custom:write property='dayofweek'/>&dayofmonth<custom:write property='dayofmonth'/>";
	strUrl=strUrl+"&<%= OvalTools.randomURL() %>";
    parent.location.href = strUrl;
}
</script>
</head>
<body>
	<form name="cform" method="post" action="<%=contextPath%>/Dispatcher">
    <input type="hidden" name="pagename" value="p_beforevisitplanmain">
    <input type="hidden" name="actionname">
    <custom:hidden property="customerid"/>
     <custom:hidden property="orgid" value="1"/>
    <custom:hidden property="contactid"/>
    <custom:hidden property="year"/>
    <custom:hidden property="monthofyear"/>
    <custom:hidden property="weekofmonth"/>
    <custom:hidden property="dayofweek"/>
    <custom:hidden property="dayofmonth"/>
    <custom:hidden property="ishistory"/>	
    <custom:hidden property="processid"/>
    <custom:hidden property="uprocessid"/>
    <custom:hidden property="globalpccode"/>
    <custom:hidden property="vflag"/>
    <custom:hidden name="visitplandetailinfo" property="planvisitdate"/>	
    <custom:hidden name="visitplandetailinfo" property="flag"/>
    <table width="100%" cellspacing="0" border="0" cellpadding="0" style='word-break:break-all;'>     
      <tr>
        <td>          
          <table width="100%" border="0" cellspacing="0">           
            <tr><td class="summary_top"></td></tr>
            <tr><td ><%=label.getLabelName("L_BasicInfo")%><%=label.getLabelName("L_Colon")%></td></tr>            
          </table>
        </td>
      </tr>
      <tr>
        <td>
          <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
             <tr > 
          			<td width="10%"><%=label.getLabelName("L_VisitDate")%></td>
          			<td colspan="3"><%=sdf.format(planToday)%>(<%=strWeekShow%>)</td>
          			
          	</tr>
          	<tr > 
          			<td width="10%"><%=label.getLabelName("L_CustomerInfo")%></td>
          			<td width="40%">
          				<custom:write name="visitplandetailinfo" property="customercode"  nbsp="true"/>
          				&nbsp;
          				<custom:write name="visitplandetailinfo" property="customername"  nbsp="true"/>
          				&nbsp;
          				<custom:write name="visitplandetailinfo" property="globalpcname"  nbsp="true"/>
          				
          			</td>
          			
          			<td width="10%"><%=label.getLabelName("L_Status")%></td>
          			<td width="40%">
          				&nbsp;<custom:write name="visitplandetailinfo" property="plandetailstatus" dictType="Status" />
          			</td>
          			
          	</tr>
          	<tr > 
          			<td width="10%"><%=label.getLabelName("L_VisitProcess")%></td>
          			<td width="40%" ><custom:write  property="processnames" nbsp="true"/></td>
          			<td width="10%"><%=label.getLabelName("L_CreateDate")%></td>
          			<td width="40%"><custom:write name="visitplandetailinfo" property="createdate" dataType="date" dataFormatName="dateformat" nbsp="true"/></td>
          			
          	</tr>
          	<%
          	java.text.SimpleDateFormat sdf2Time=new java.text.SimpleDateFormat("HH:mm");
          	HashMap visitplandetailinfo=(HashMap)pageContext.getAttribute("visitplandetailinfo");
          	if(visitplandetailinfo==null)
          		visitplandetailinfo=new HashMap();
          	
          			Date dStart=(Date)visitplandetailinfo.get("planstarttime");
          			Date dEnd=(Date)visitplandetailinfo.get("planendtime");
          			Integer plandetailstatus=(Integer)visitplandetailinfo.get("plandetailstatus");
          			String sStart="";
          			String sEdit="";
          			if(dStart!=null)
          				sStart=sdf2Time.format(dStart);
          			if(dEnd!=null)
          				sEdit=sdf2Time.format(dEnd);
          	%>
          	<tr > 
          			<td width="10%"><%=label.getLabelName("L_LastVisitDate")%></td>
          			<td width="40%" ><custom:write name="lastvisitdate" property="lastvisitdate"  nbsp="true"/></td>
          			<td width="10%"><%=label.getLabelName("L_CountVisitOfMonth")%></td>
          			<td width="40%"><custom:write name="visitcount" property="count_org"  nbsp="true"/></td>
          	</tr>
          	   	
          	
          	<%
          	HashMap feedbackinfo=(HashMap)pageContext.getAttribute("feedbackinfo");
          	if(feedbackinfo==null)
          		feedbackinfo=new HashMap();
          	Integer oStatus=(Integer)feedbackinfo.get("status");
          
          	if(oStatus!=null && oStatus.intValue()==99)
          		pageContext.setAttribute("displayflag","view");
          			Date dActualStart=(Date)feedbackinfo.get("starttime");
          			Date dActualEnd=(Date)feedbackinfo.get("endtime");
          			String sActualStart="";
          			String sActualEdit="";
          			if(dActualStart!=null)
          				sActualStart=sdf2Time.format(dActualStart);
          			if(dActualEnd!=null)
          				sActualEdit=sdf2Time.format(dActualEnd);
          	%>
          	<!-- 
          	<tr > 
          			<td width="120"><%=label.getLabelName("L_VisitActualStartTime")%></td>
          			<td  ><input type="text" name="sstarttime" value="<%=sActualStart%>"/>
          				<input type="hidden" name="starttime" value="<%=sActualStart%>"/>
          				</td>
          			<td width="120"><%=label.getLabelName("L_VisitActualEndTime")%></td>
          			<td ><input type="text" name="sendtime" value="<%=sActualEdit%>"/>
          				<input type="hidden" name="endtime" value="<%=sActualEdit%>"/>
          				</td>
          			
          	</tr>
          	
          	 -->
          	 <input type="hidden" name="starttime" value="<%=sActualStart%>"/>
          	 <input type="hidden" name="endtime" value="<%=sActualEdit%>"/>
          	<!-- 
          	<tr> 
          		<td><%=label.getLabelName("L_VisitDate")%></td>
          		<td colspan="3">
                <custom:text name="feedbackinfo" property="visitdate" dataType="date" label="L_VisitDate" dataFormatName="dateformat"  size="20" command="notnull" readonly="true"/>
                 <a onclick="show_calendar('cform.visitdate','<%= session.getAttribute("dateformat")%>');"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
                <a onclick="javascript:c.show(this,'cform.visitdate','yyyy-MM-dd');"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
              </td>                  			
          	</tr>  
          	-->        	 
          	<tr > 
          			<td width="10%"><%=label.getLabelName("L_BriefDescription")%></td>
          			<td  colspan="3"><custom:textarea name="feedbackinfo" property="description" cols="80"  rows="4"/></td>
          			
          	</tr>
          </table>
          
        </td>
      </tr>
      <%@ include file="/sfe/VisitPlanMain.inc"%>
      <tr>
      	<td>
      		<table width="100%" cellspacing="0" cellpadding="0">
            <tr>
            	<td class="summary_top">
            	<input type="hidden" name="numrows" value="<%=num%>"/>
            	</td>
            </tr>
            <tr>
              <td class="td_center">
              	<%
              	Calendar nowcal = Calendar.getInstance();
            	Calendar  numcal = Calendar.getInstance();
            	numcal.clear();
            	numcal.set(Calendar.YEAR, nYear);
            	numcal.set(Calendar.MONTH, nMonth - 1);
            	numcal.set(Calendar.WEEK_OF_MONTH, nWeek);
            	numcal.set(Calendar.DAY_OF_WEEK, nDay);
            	numcal.add(Calendar.DATE,1);
            	//out.print(new java.sql.Date(((Date)nowcal.getTime()).getTime()));
            	//out.print(new java.sql.Date(((Date)numcal.getTime()).getTime()));
            	if (nCurUserId.equals(contactid)) {
            		if(numcal.compareTo(nowcal)>0){	
            		  if(plandetailstatus.intValue()==10){
              	%>
              	<a onclick="page_confirm();"><custom:button type="1" label="L_Confirm" imgsrc="new.gif" border="0" style="width:60"/></a>
                <%       }
                     }
            	}%>
             <!--  
           <%//} if(oStatus!=null && oStatus.intValue()==10){%>
             <a onclick="page_closefeedback();"><custom:button type="1" label="L_CloseFeedBack" imgsrc="new.gif" border="0" style="width:100"/></a>
            -->    
                  <a onclick="page_back();"><custom:button type="1" label="L_Back" imgsrc="new.gif" border="0" style="width:60"/></a>
              </td>
            </tr>
          </table>  
        </td>
      </tr>
    </table>
  </form>   
  <%@ include file ="/sfe/VisitPlanMainJs.inc" %>      	
</body>

</html>
	
